﻿using System;
using Game.Kernel;

namespace Game.Logic
{
    public enum GameStatus
    {
        Invalid = 0,
        Init,
        ConnectServer,
        EnterLogin,
        GetVersion,
        CheckVersion,
        Downloading,
        EnterGame,

    }


    public enum GameControllerStatus
    {
        Invalid = 0,

    }

    public delegate void OnUpdateGameStatus(GameStatus _cur, GameStatus _pre);

    public class GameController : GameBaseController
    {
        private GameState m_gameState;
        public GameState GameState { get => m_gameState; private set => m_gameState = value; }

        private GameStatus m_gameStatus;
        public GameStatus GameStatus { get => m_gameStatus; private set => m_gameStatus = value; }


        public GameController()
        {
            InitGameModel();
        }

        private void InitGameModel()
        {
            GameModel model = new GameModel();
            RegisterGameStatusUpdateHanler(model.OnUpdateGameStatus);
            Model = model;
        }


        public void Start()
        {
            SetGameStatus(GameStatus.Init);
        }


        #region Update GameStatus Event
        private event OnUpdateGameStatus m_updateGameStatus;
        public void RegisterGameStatusUpdateHanler(OnUpdateGameStatus _handler)
        {
            m_updateGameStatus += _handler;
        }
        public void UnregisterGameStatusUpdateHanler(OnUpdateGameStatus _handler)
        {
            m_updateGameStatus -= _handler;
        }
        public void DispatchUpdateGameStatue(GameStatus _cur, GameStatus _pre)
        {
            m_updateGameStatus?.Invoke(_cur, _pre);
        }
        #endregion



        #region Game Status Interface
        public void SetGameStatus(GameStatus _gameStatus)
        {
            GameStatus pre = GameStatus;
            GameStatus = _gameStatus;
            DispatchUpdateGameStatue(GameStatus, pre);
        }
        #endregion
    }
}


